package ro.ubbcluj.cs.bs.api.util;

import ro.ubbcluj.cs.bs.backend.service.exception.BiblioSpringServiceException;

import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

/**
 * Created by Levente on 2014.05.22..
 */
@Provider
public class ApiExceptionMapper implements ExceptionMapper<Exception> {
    @Override
    public Response toResponse(final Exception ex) {
        ex.printStackTrace();
        if (ex instanceof BiblioSpringServiceException) {
            return Response.status(Response.Status.BAD_REQUEST).entity(ex.getMessage()).build();
        }

        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ex.getMessage()).build();
    }
}
